
package JET.MouseStuff.SpecialTasks;

import JET.Centers.ControlCenter;
import JET.MouseStuff.Task;
import JET.SA.SA_Face;
import JET.Scene;
import JET.SceneHelper;
import JET.StaticActions;
import JET.graphics.elements.Face;
import JET.physics.Mass;
import JET.physics.bodies.SpringBody;
import java.util.Collection;

/**
 *
 * @author 057Ry
 */
public class CreateSringBodyFace implements Task{

    private Scene scene;

    public CreateSringBodyFace(Scene s) {
        scene = s;
    }

    public boolean needKeyConfirmationToProceed() {
        return false;
    }

    public int getKeyCode() {
        return 0;
    }

    public boolean canProceed() {
        return true;
    }

    public void execute() {
        ControlCenter CC = ControlCenter.getInstance();

//        SpringBody sb = scene.getEngine().getSpringBodyThatOwnMass(scene.EC.savedSelectionGroup1.getMassList().get(0));
        SpringBody sb = SceneHelper.getSpringBodyThatOwnMass(scene, scene.EC.savedSelectionGroup1.getMassList().get(0));
        Collection<Mass> massCol = scene.EC.savedSelectionGroup1.getMassListSync();
        synchronized(massCol) {
            for(Mass m : massCol)
//                if (!scene.getEngine().getSpringBodyThatOwnMass(m).equals(sb)) {
                if (!SceneHelper.getSpringBodyThatOwnMass(scene, m).equals(sb)) {
                    System.out.println("Masses selected of not single spring body!");
                    return;
                }
        }

        Face f = new Face(scene.EC.savedSelectionGroup1.getMassList());
        System.out.println("Face : "+f);

        SA_Face.addFaceToSpringBody(f, sb, true);
    }

}
